package com.example.mymvvmdemo.net.presenter;


import com.example.mymvvmdemo.MyApplication;
import com.example.mymvvmdemo.net.model.GetModel;
import com.example.mymvvmdemo.net.model.IModel;
import com.example.mymvvmdemo.net.view.IView;
import com.example.mymvvmdemo.utils.LogUtils;

import java.util.HashMap;

/**
 * 普通get请求统一presenter
 */
public class GetPresenter implements IModel.GetModel {

    private GetModel getModel = new GetModel(this);

    private IView.GetView getView;

    public GetPresenter(IView.GetView getView) {
        this.getView = getView;
    }

    public void startLoadGet(String url, HashMap<String, String> hashMap, String type) {
        getModel.startLoadGet(url, MyApplication.getAuthToken(), hashMap, type);
    }


    //回调给view
    @Override
    public void loadGetSuccess(String result, String type, int code) {
        LogUtils.d("load get success type:" + type + ",result:" + result);
        LogUtils.printJson(result, type);
        getView.loadGetSuccess(result, type, code);
    }

    @Override
    public void loadGetFail(String message, String type) {
        LogUtils.d("load get fail type:" + type + ",message:" + message);
        getView.loadGetFail(message, type);
    }

    @Override
    public void loadGetAccountError(int code) {
        LogUtils.d("load get account error code :" + code);
        getView.loadGetAccountError(code);
    }

    @Override
    public void loadGetNetWorkError(String message) {
        LogUtils.d("load get network error :" + message);
        getView.loadGetNetWorkError();
    }

}
